package com.ls.kdlss.ui.bangbang;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;

import com.gm.common.utils.ActivityUtil;
import com.gm.common.utils.ToastUtil;
import com.gm.lib.views.titlebar.AbTitleBar;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.ls.kdlss.R;
import com.ls.kdlss.util.HttpStorage;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;


/**
 * Created by Administrator on 2016/11/18.
 */

public class TeachanswersActivity extends AppCompatActivity {


    @Bind(R.id.title_bar)
    AbTitleBar titleBar;
    @Bind(R.id.xr_view)
    XRecyclerView xrView;
    private String TAG;
    private CommonAdapter<String> commonAdapter;
    public static void launch(Context context) {
        ActivityUtil.startActivity(context, TeachanswersActivity.class);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teachanswers);
        ButterKnife.bind(this);
        setViews();
    }


    public void setViews() {
        setMasserg();
        titleBar.setTitleText("老师回答");
        titleBar.setLeftVisible();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(TeachanswersActivity.this);
        xrView.setLayoutManager(linearLayoutManager);
        List<String> strings = new ArrayList<>();
        strings.add("");
        strings.add("");
        strings.add("");
        strings.add("");
        strings.add("");

        commonAdapter = new CommonAdapter<String>(TeachanswersActivity.this, R.layout.cell_news, strings) {
            @Override
            protected void convert(ViewHolder holder, String s, int position) {



            }
        };
        xrView.setAdapter(commonAdapter);


    }



    public void setMasserg(){

        OkHttpClient client=new OkHttpClient();
        final Request request=new  Request.Builder().url(HttpStorage.MassageUsrls()).build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

                final String body=response.body().string();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtil.show(body);
                        Log.e(TAG,body);
                    }
                });

            }
        });


    }


}
